package com.xjc.business.controller.buildadmin;

import com.xjc.business.entity.po.buildadmin.RepairApplyUpdatePo;
import com.xjc.business.entity.vo.buildadmin.BuildRepairApplyVo;
import com.xjc.business.service.StudentRepairApplysService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 徐锦程
 * 时间:2025-03-08 10:55
 */
@RestController
@RequestMapping("/build_admin/repair_apply")
public class BuildRepairApplyController {

    @Autowired
    StudentRepairApplysService studentRepairApplysService;

    /**
     * 获取报修申请列表
     * @param id 宿管Id
     * @return 数据
     */
    @GetMapping("/get_repair_apply_list/{id}")
    public Result<List<BuildRepairApplyVo>> getRepairApplyList(@PathVariable(required = false, value = "id") Integer id) {
        if(id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentRepairApplysService.getRepairApplyList(id);
    }

    /**
     * 更新状态
     * @return 数据
     */
    @PostMapping("/update_status")
    public Result<String> updateStatus(@RequestBody(required = false) RepairApplyUpdatePo repairApplyUpdatePo) {
        if(repairApplyUpdatePo == null || repairApplyUpdatePo.getId() == null || repairApplyUpdatePo.getStatus() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentRepairApplysService.updateStatus(repairApplyUpdatePo);
    }
}